<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/blogger.css">
    <link rel="stylesheet" href="./css/blog_content.css">
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <!-- <link rel="stylesheet" href="editor.md/css/editormd.min.css" /> -->
</head>

<body onload="getInfo()">

    <iframe src="i_nav.html" style="height: 45px; width: 100%;" frameborder="0"></iframe>

    <div class="container">
        <iframe src="i_blogger.html" style="height: 534px; width: 274px;" frameborder="0"></iframe>

        <div class="blogs">
            <h3 id="title"></h3>
            <div id="date"></div>
            <div id="content"></div>
        </div>
    </div>


    <script>
        //信息获取
        function getInfo() {
            //登录验证
            if (localStorage.getItem('token')) {

                //博客内容
                const title = document.querySelector('#title')//博客标题
                const date = document.querySelector('#date')//日期
                const content = document.querySelector('#content')//博客内容

                //博客内容获取
                const id = new URLSearchParams(window.location.search).get('id');
                axios(`http://47.98.20.202:8000/topics/${id}/getTopicDetail/`)
                    .then(res => {
                        const time = formatTime(res.data.data.create_time);

                        title.innerHTML = res.data.data.t_title;
                        date.innerHTML = time;
                        content.innerHTML = res.data.data.t_content;
                    }).catch(err => {
                        console.log(err);
                    })
            }
            else {
                window.location.href = "login.html";
            }


            //时间戳转换为时间
            function formatTime(time) {
                const date = new Date(time * 1000);
                const Y = date.getFullYear();
                const M = date.getMonth() + 1;
                const D = date.getDate();
                const h = date.getHours();
                const m = date.getMinutes();
                return `${Y}-${M}-${D} ${h}:${m}`;
            }
        }
    </script>
</body>

</html>